package com.atguigu.controller;

import com.atguigu.client.CartFeignClient;
import com.atguigu.client.ProductFeignClient;
import com.atguigu.entity.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class WebCartController {
    @Autowired
    private CartFeignClient cartFeignClient;
    @Resource
    private ProductFeignClient productFeignClient;
    //点击跳转到购物车的界面
    @GetMapping("addCart.html")
    public String addCart(@RequestParam Long skuId,
                          @RequestParam Integer skuNum,
                          HttpServletRequest request){
        //添加到购物车
        cartFeignClient.addToCart(skuId,skuNum);
        //获取信息返回给页面显示商品信息
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);
        return "cart/addCart";
    }
    //2.购物车列表展示
    @GetMapping("cart.html")
    public String cartList(){
        return "cart/index";
    }
}
